from . import DEFAULT_MODEL_NAME, Prompt, client

USER_PROMPT = """
{prompt}

以下是需要极简化处理的详细答案：
{detailed_answer}

请按照上述要求对答案进行极简化处理，要求简化后的答案控制在100个字符以内。
"""


def build_prompt(prompt: str, detailed_answer: str) -> Prompt:
    user_prompt = USER_PROMPT.format(prompt=prompt, detailed_answer=detailed_answer)
    return Prompt(system_prompt="", user_prompt=user_prompt)


async def run_agent(prompt: str, detailed_answer: str) -> str:
    """Run the simplify answer agent.

    Args:
        prompt: The simplification prompt/instruction.
        detailed_answer: The detailed answer to be simplified.
    
    Returns:
        str: The simplified answer.
    """
    prompt_obj: Prompt = build_prompt(prompt, detailed_answer)
    chat_completion = await client.chat.completions.create(
        messages=[
            {"role": "system", "content": ""},
            {"role": "user", "content": prompt_obj.user_prompt},
        ],
        model=DEFAULT_MODEL_NAME,
    )
    response = chat_completion.choices[0].message.content
    return response
